﻿Imports Paintbear.PaintbearDrawing
Public Class frmMain
    Dim SavedFileAdress As String = ""
    Private _currentDrawing As PaintbearDrawing
    Public Sub CreMen(ByVal MenuItem As MenuItem)
        Dim Menu As New PaintbearMenuItem
        MenuItem.MenuItems.Add(Menu)
        Menu.Text = openImage.FileName
    End Sub
    Private Sub MenuItem10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem10.Click
        drawBox.BackColor = Color.White
        drawBox.Width = 640
        drawBox.Height = 480
        drawBox.Dock = DockStyle.None
        drawBox.BackgroundImage = Nothing
        Me.Text = "Paintbear 0.9(bt09t)"
        statusLbl.Text = ""
        frmNewImage.Show()
    End Sub

    Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        e.Cancel = True
        frmCancelClose.Show()
    End Sub

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub MenuItem105_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem105.Click
        frmAbout.Show()
    End Sub

    Private Sub MenuItem12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem12.Click
        drawBox.BackColor = Color.White
        drawBox.BackgroundImage = Nothing
        drawBox.Width = 640
        drawBox.Height = 480
        drawBox.Dock = DockStyle.None
        Me.Text = "Paintbear 0.9(bt09t)"
        statusLbl.Text = ""
        With openImage
            .Title = "Open a image"
            .Filter = "Bitmap (*.bmp)|*.bmp|Portable Network Graphic (*.png)|*.png|Monochrome-Bitmap (*.dib)|*.dib|TIF-File (*.tif)|*.tif|JPG-File (*.jpg)|*.jpg|JPEG-File (*.jpeg)|*.jpeg|SVG-File (*.svg)|*.svg|Icon (*.ico)|*.ico|Chrome-DAB (*.dab)|*.dab|Mono-Chrome-DAB (*.chrome)|*.chrome|GIF-Image (*.gif)|*.gif|JPE-File (*.jpe)|*.jpe|JFIF-File (*.jfif)|*.jfif|Chrome-DASB (*.dasb)|*.dasb|ImageBear (*.imgbear)|*.imgbear"
            If .ShowDialog() = Windows.Forms.DialogResult.OK Then
                MenuItem17.Enabled = True
                MenuItem65.Enabled = True
                Dim bmp As New Bitmap(openImage.FileName)
                _currentDrawing = New PaintbearDrawing(bmp)
                drawBox.Height = bmp.Height
                drawBox.Width = bmp.Width
                drawBox.BackgroundImageLayout = ImageLayout.None
                mainPanel.Size = bmp.Size
                Me.Text = "[" & openImage.SafeFileName & "]" & " - Paintbear 0.9(bt09t)"
                MenuItem15.Visible = False
                CreMen(MenuItem14)
                statusLbl.Text = openImage.FileName
            End If
        End With
    End Sub

    Private Sub openImage_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles openImage.FileOk
        
    End Sub

    Private Sub MenuItem14_Select(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuItem14.Select

    End Sub

#Region "RotateFlip"
    Private Sub MenuItem132_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem132.Click
        drawBox.BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipNone)
    End Sub

    Private Sub MenuItem133_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem133.Click
        drawBox.BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipX)
    End Sub

    Private Sub MenuItem134_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem134.Click
        drawBox.BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipXY)
    End Sub

    Private Sub MenuItem135_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem135.Click
        drawBox.BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipY)
    End Sub

    Private Sub MenuItem137_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem137.Click
        drawBox.BackgroundImage.RotateFlip(RotateFlipType.Rotate180FlipNone)
    End Sub

    Private Sub MenuItem138_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem138.Click
        drawBox.BackgroundImage.RotateFlip(RotateFlipType.Rotate180FlipX)
    End Sub

    Private Sub MenuItem139_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem139.Click
        drawBox.BackgroundImage.RotateFlip(RotateFlipType.Rotate180FlipXY)
    End Sub

    Private Sub MenuItem140_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem140.Click
        drawBox.BackgroundImage.RotateFlip(RotateFlipType.Rotate180FlipY)
    End Sub

    Private Sub MenuItem142_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem142.Click
        drawBox.BackgroundImage.RotateFlip(RotateFlipType.Rotate270FlipNone)
    End Sub

    Private Sub MenuItem143_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem143.Click
        drawBox.BackgroundImage.RotateFlip(RotateFlipType.Rotate270FlipX)
    End Sub

    Private Sub MenuItem144_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem144.Click
        drawBox.BackgroundImage.RotateFlip(RotateFlipType.Rotate270FlipXY)
    End Sub

    Private Sub MenuItem145_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem145.Click
        drawBox.BackgroundImage.RotateFlip(RotateFlipType.Rotate270FlipY)
    End Sub
#End Region

    Private Sub chPItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chPItem.Click
        frmPen.Show()
        chPItem.Checked = True
        modeItem.Checked = True
    End Sub

    Private Sub modeItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles modeItem.Click
        frmPen.Show()
        chPItem.Checked = True
        modeItem.Checked = True
    End Sub

    Private Sub coItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles coItem.Click
        frmColors.Show()
        coItem.Checked = True

    End Sub

    Private Sub MenuItem100_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem100.Click
        Application.Restart()
    End Sub

    Private Sub MenuItem102_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem102.Click
        Application.Restart()
        Application.ExitThread()
    End Sub

    Private Sub MenuItem30_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem30.Click
        End
    End Sub

    Private Sub MenuItem28_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem28.Click
        drawBox.BackColor = Color.White
        drawBox.BackgroundImage = Nothing
        drawBox.Width = 640
        drawBox.Height = 480
        drawBox.Dock = DockStyle.None
        Me.Text = "Paintbear 0.9(bt09t)"
        statusLbl.Text = ""
    End Sub

    Private Sub MenuItem18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem18.Click
        If SavedFileAdress = "" Then
            saveImage.Filter = "Bitmap (*.bmp)|*.bmp|Portable Network Graphic (*.png)|*.png|Monochrome-Bitmap (*.dib)|*.dib|TIF-File (*.tif)|*.tif|JPG-File (*.jpg)|*.jpg|JPEG-File (*.jpeg)|*.jpeg|Icon (*.ico)|*.ico|Chrome-DAB (*.dab)|*.dab|Mono-Chrome-DAB (*.chrome)|*.chrome|GIF-Image (*.gif)|*.gif|JPE-File (*.jpe)|*.jpe|JFIF-File (*.jfif)|*.jfif|Chrome-DASB (*.dasb)|*.dasb|ImageBear (*.imgbear)|*.imgbear"
            saveImage.Title = "Save this image"
            If saveImage.ShowDialog = Windows.Forms.DialogResult.OK Then
                Try
                    SavedFileAdress = saveImage.FileName
                    drawBox.BackgroundImage.Save(saveImage.FileName)
                    Me.Text = "[" & saveImage.FileName & "]" & " - Paintbear 0.9(bt09t)"
                    statusLbl.Text = saveImage.FileName
                Catch
                    MsgBox("error! Visit 'Debug-console' or 'Paintbear-status' for more informations !", MsgBoxStyle.Critical)
                    'Eine Ausnahme (erste Chance) des Typs "System.Runtime.InteropServices.ExternalException" ist in System.Drawing.dll aufgetreten.
                    debug_console.consoleBox.Text = debug_console.consoleBox.Text & vbCrLf & vbCrLf & "An exception(first chance) of type 'System.Runtime.InteropServices.ExternalException' has occured in 'System.Drawing.dll'."
                    paintbear_status.MetroTracker1.Value = 100
                    paintbear_status.MetroTracker1.ValueTwo = 50
                    paintbear_status.MetroTracker1.ValueThree = 85
                End Try
            Else
                drawBox.BackgroundImage.Save(saveImage.FileName)
            End If
        End If
    End Sub

    Private Sub MenuItem44_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem44.Click
        debug_console.Show()
    End Sub

    Private Sub MenuItem45_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem45.Click
        paintbear_status.Show()
    End Sub
End Class